package com.tedu.controller;

import com.tedu.pojo.Article;
import com.tedu.pojo.ResultVO;
import com.tedu.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author：毕龙
 * Date: 2023/12/23 10:31
 */
@RestController
@RequestMapping("/article")
@Slf4j
public class ArticleController {

    public ArticleController(){
        log.debug("创建控制层ArticleController对象");
    }

    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public ResultVO<Article> listArticle(){
        ResultVO<Article> resultVO = articleService.listArticle();
        return resultVO;
    }

    @PostMapping("/insert0")
    public ResultVO<String> listArticle0(@RequestBody Article article){
        ResultVO<String> resultVO = articleService.insertArticle(article);
        return resultVO;
    }
    @PostMapping("/insert1")
    public ResultVO<String> listArticle1(Article article){
        ResultVO<String> resultVO = articleService.insertArticle(article);
        return resultVO;
    }
    @PostMapping("/insert2/{title}/{content}")
    public ResultVO<String> listArticle2(@PathVariable String title,
                                         @PathVariable String content){
        ResultVO<String> resultVO = articleService.insertArticle(
                new Article().setTitle(title).setContent(content)
        );
        return resultVO;
    }


    @GetMapping("/get/{id}")
    public ResultVO<Article> getArticleById(@PathVariable Integer id){
        return articleService.getArticleById(id);
    }

    @PutMapping("/update")
    public ResultVO<Article> updateArticle0(@RequestBody Article article){
        ResultVO<Article> resultVO = articleService.updateArticleById(article);
        return resultVO;
    }

    @DeleteMapping("/delete/{id}")
    public ResultVO<Article> deleteArticleById(@PathVariable Integer id){
        ResultVO<Article> resultVO = articleService.deleteArticleById(id);
        return resultVO;
    }

}
